<?php
require_once 'data_form'.EXT;

class h_s extends data_form{

	function __construct(){
		parent::__construct();
	}
	
	function index()
	{
		$row	=	null;
		$this->load->model('hss_model');
		$row	=	$this->hss_model->get_by(array('customer_id' => $_SESSION['customer']['id']));
		
		if($_SERVER["REQUEST_METHOD"]  == "POST")
		{
			$data	=	array(
				'customer_id'	=>	$_SESSION['customer']['id'],
				'preferred'		=>	(isset($_POST['Pref']) ? $_POST['Pref'] : ''),
				'p_number_bed'	=>	$_POST['select'],
				'p_coinsurance'	=>	(isset($_POST['CoInsurance']) ? 1 : 0),
				'p_deductible'	=>	(isset($_POST['Deductible']) ? 1 : 0),
				'existing'		=>	(isset($_POST['exis']) ? $_POST['exis'] : ''),
				'e_number_bed'	=>	$_POST['select2'],
				'e_coinsurance'	=>	(isset($_POST['CoInsurance2']) ? 1 : 0),
				'e_deductible'	=>	(isset($_POST['Deductible2']) ? 1 : 0),
				'has_the_same'	=>	$_POST['select3']
			);
			$id	=	null;
			if($row)
			{
				//update data
				$this->hss_model->update($row->id,$data);
				$id	=	$row->id;
			}
			else
			{
				//insert new data
				$id	=	$this->hss_model->insert($data);
			}
			//print_r($_POST);
			$row	=	$this->hss_model->get($id);
		}
		$this->data['row']	=	$row;
		$this->load->view("h_s/index", $this->data);
	}

}